// 配置vite在html文件中使用环境变量
import { createHtmlPlugin as viteHtmlPlugin } from 'vite-plugin-html-transform';

export default function createViteHtmlPlugin(env) {
  const { RUN_PROJECT, PROJECT_NAME } = process.env;
  return viteHtmlPlugin({
    inject: {
      minify: true,
      data: {
        ...env,
        ...process.env,
        injectScript: '<script type="module" src=""></script>',
        injectJQuery: '<script src="https://cdn.bootcdn.net/ajax/libs/jquery/2.2.2/jquery.min.js"></script>', // JQuery
        injectBMapAK: '<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=PlhFWpA02aoURjAOpnWcRGqw7AI8EEyO"></script>', // 百度地图AK
        injectBMap: '<script type="text/javascript" src="http://developer.baidu.com/map/custom/stylelist.js"></script>',
        injectAMap: '<script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=981d75c46d5c6688f8e88b398a47f9a7"></script>', // 高德地图AK
        injectTitle: `<title>${PROJECT_NAME || env.VITE_PROJECT_NAME}</title>`, // 网站标题
        injectMain: `<script type="module" src="/src/views/${RUN_PROJECT}/main.js"></script>`
      }
    }
  });
}
